#include #include #include using namespace std; const unsigned int HEADER_SIZE = 54; const unsigned int BYTES_PER_PIXEL = 3; const char HEART = (char)3; const char DIAMOND = (char)4; const char CLUB = (char)5; const char SPADE = (char)6; //encapsulation - grouping data and functionality that "belong together" //cohesion - tight //coupling - loose //constructor - a function for a User Defined Data-Type that is called automaticaly // when an object of that type is created, it does not have a return type //destructor - a function for a User Defined Data-Type that is called automaticaly // when an object of that type is destroyed (goes out of scope) // In a destructor you would typically delete dynamicly allocated memory or close files struct PlayingCard { string faceValue; char suit; void display(); }; struct Hand { PlayingCard cards[13]; void display(); }; struct Deck { PlayingCard cards[52]; Deck(); ~Deck(); void initialize(); void display(); void shuffle(); void deal(Hand hands[]); }; void PlayingCard::display() { cout << faceValue << " of " << suit; } Deck::Deck() { initialize(); } Deck::~Deck() { cout << "The deck destructor was called\n"; } void Deck::display() { for(int i = 0; i < 52;i++) { cards[i].display(); cout << endl; } } void Deck::deal(Hand hands[]) { int i = 0; for(int card = 0; card < 13; card++) { for(int hand = 0; hand < 4; hand++) { hands[hand].cards[card] = cards[i]; i++; } } } void Deck::shuffle() { for(int i = 0; i < 100000;i++) { int card1 = rand() % 52; int card2 = rand() % 52; PlayingCard temp = cards[card1]; cards[card1] = cards[card2]; cards[card2] = temp; } } //:: scope resoultion operator void Deck::initialize() { int i = 0; for(int suit = 0; suit < 4; suit++) { for(int faceValue = 0; faceValue < 13; faceValue++) { switch(suit) { case 0: cards[i].suit = HEART; break; case 1: cards[i].suit = CLUB; break; case 2: cards[i].suit = DIAMOND; break; case 3: cards[i].suit = SPADE; break; } switch(faceValue) { case 0: cards[i].faceValue = "2"; break; case 1: cards[i].faceValue = "3"; break; case 2: cards[i].faceValue = "4"; break; case 3: cards[i].faceValue = "5"; break; case 4: cards[i].faceValue = "6"; break; case 5: cards[i].faceValue = "7"; break; case 6: cards[i].faceValue = "8"; break; case 7: cards[i].faceValue = "9"; break; case 8: cards[i].faceValue = "10"; break; case 9: cards[i].faceValue = "Jack"; break; case 10: cards[i].faceValue = "Queen"; break; case 11: cards[i].faceValue = "King"; break; case 12: cards[i].faceValue = "Ace"; break; } i++; } } } void Hand::display() { for(int i = 0; i < 13;i++) { cards[i].display(); cout << endl; } } void main() { srand(time(NULL)); { Deck r; } Deck deck; Hand hands[4]; // deck.initialize(); deck.shuffle(); deck.deal(hands); hands[0].display(); // deck.display(); }